import Vuex from "vuex"
import createPersistedState from 'vuex-persistedstate'
import utils from '../utils'

export default new Vuex.Store({
    state: {
        plans: []
    },
    mutations: {
        addPlan(state, item) {
            state.plans.push(item)
        },
        deletePlan(state, item) {
            let index = utils.indexOf(item, state.plans)
            if (index > -1) {
                state.plans.splice(index, 1);
            }
        }
    },
    plugins: [
        createPersistedState() // 注入持久化的插件，将vuex中的数据存储到localStorerage中
    ]
})